package com.itheima.d5_集合嵌套;

import java.util.*;

/**
 * 某个班级80个学生，班长提供了 A B C D四个景点， 每个学生选多个景点；统计出最终哪个景点
 * 下次遇到景点的问题 还是要用 A=40,这样的方式
 */
public class Test {
    public static void main(String[] args) {
        String[] spots = {"A", "B", "C", "D"};
        Map<Student, Set<String>> maps = new HashMap<>();
        Random random = new Random();
        for (int i = 0; i < 80; i++) {
            Student student = new Student();
            Set<String> sets = new HashSet<>();
            student.setName("student" + i);
            int index = random.nextInt(spots.length);
            for (int j = 0; j <= index; j++) {
                sets.add(spots[j]);
            }
            maps.put(student, sets);

        }
        System.out.println(maps);
        Map<String,Integer> infos = new HashMap<>();
        Collection<Set<String>> values = maps.values();
        // [[A],[A,B,C,D]]
        for (Set<String> value : values) {
            for (String s : value) {
                if (infos.containsKey(s)){
                    infos.put(s,infos.get(s)+1);
                }else{
                    infos.put(s,1);
                }
            }
        }
        System.out.println(infos);
    }
}
class Student {
    private String name;


    public Student() {
    }

    public Student(String name) {
        this.name = name;

    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                '}';
    }
}